import { usePageRequest } from "../../../utils/request";

Component({
    data: {
        status: 0,
    },
    methods: {
        onLoad() {
            this.listRequest = new usePageRequest('api/searchinfolist', { hold: true }, this)
            this.dynamicRequest = new usePageRequest('api/searchtourismlist', { hold: true }, this)
        },
        onShow() {
            this.getTabBar().init();
            wx.startPullDownRefresh()
        },
        changeStatus(e) {
            const index = Number(e.detail.index)
            this.setData({
                status: index
            })
            wx.startPullDownRefresh()
        },
        onPullDownRefresh() {
            this.setData({
                message: ''
            })
            switch (this.data.status) {
                case 1:
                    this.listRequest.reset({}).then(() => {
                        wx.stopPullDownRefresh()
                    })
                    break;
                case 0:
                    this.dynamicRequest.reset({}).then(() => {
                        wx.stopPullDownRefresh()
                    })
                    break;
            }
        },
        async search() {
            switch (this.data.status) {
                case 1:
                    this.listRequest.reset({
                        title: this.data.message
                    })
                    break;
                case 0:
                    this.dynamicRequest.reset({
                        title: this.data.message
                    })
                    break;
            }
        },
        onReachBottom() {
            switch (this.data.status) {
                case 1:
                    this.listRequest.next()
                    break;
                case 0:
                    this.dynamicRequest.next()
                    break;
            }
        },
        toAdd() {
            wx.navigateTo({
                url: '/pages/dynamic/edit/edit?type=1'
            })
        }
    }
})
